﻿//===============================================================================
// Microsoft patterns & practices Enterprise Library Contribution
// Mapping Application Block
//===============================================================================

using System.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;

namespace EntLibContrib.Mapping.Configuration
{
	/// <summary>
	/// Overall configuration settings for Mappers
	/// </summary>    
	public class MappingSettings : SerializableConfigurationSection
	{
		#region Constants
		/// <summary>
		/// Configuration key for mapping settings.
		/// </summary>
		public const string SectionName = "mappingConfiguration";
		private const string mappersProperty = "mappers";
		#endregion

		#region Properties
		/// <summary>
		/// Gets the collection of defined <see cref="IMapper"/> objects.
		/// </summary>
		/// <value>
		/// The collection of defined <see cref="IMapper"/> objects.
		/// </value>
		[ConfigurationProperty(mappersProperty, IsRequired = false)]
		public NameTypeConfigurationElementCollection<MapperBaseData, CustomMapperData> Mappers
		{
			get { return (NameTypeConfigurationElementCollection<MapperBaseData, CustomMapperData>)base[mappersProperty]; }
		}
		#endregion

		#region Construction
		/// <summary>
		/// Initializes a new instance of the <see cref="MappingSettings"/> class.
		/// </summary>
		public MappingSettings()
		{
			base[mappersProperty] = new NameTypeConfigurationElementCollection<MapperBaseData, CustomMapperData>();
		}
		#endregion

		#region Public Static Methods
		/// <summary>
		/// Gets the <see cref="MappingSettings"/> section in the configuration source.
		/// </summary>
		/// <param name="configurationSource">The <see cref="IConfigurationSource"/> to get the section from.</param>
		/// <returns>The mapping configuration section.</returns>
		public static MappingSettings GetMappingSettings(IConfigurationSource configurationSource)
		{
			return (MappingSettings)configurationSource.GetSection(SectionName);
		}
		#endregion
	}
}